import { createRouter, createWebHashHistory } from 'vue-router'

const Layout = () =>
    import ('@/views/Layout.vue')
const Home = () =>
    import ('@/views/home')
const TopCategory = () =>
    import ('@/views/category/index.vue')
const SubCategory = () =>
    import ('@/views/category/sub.vue')
const Goods = () =>
    import ('@/views/goods/index')
const Cart = () =>
    import ('@/views/cart/index')
const Login = () =>
    import ('@/views/login/index')
const LoginCallback = () =>
    import ('@/views/login/callback')


const routes = [
    //一级路由布局容器
    {
        path: '/',
        component: Layout,
        children: [
            { path: '/', component: Home },
            { path: '/category/:id', component: TopCategory },
            { path: '/category/sub/:id', component: SubCategory },
            { path: '/product/:id', component: Goods },
            { path: '/cart', component: Cart }
        ]
    },
    { path: '/login', component: Login },
    { path: '/login/callback', component: LoginCallback }
]

//创建一个路由实例
const router = createRouter({
    //使用hash方式实现路由
    history: createWebHashHistory(),
    //配置路由规则
    routes,
    scrollBehavior() {
        return { left: 0, top: 0 }
    }
})

export default router